Open
Conversation
This enables basic assertions against metadata in `rivertest.RequireX` methods. The approach here isn't anything special: it allows a `map[string]any` to be specified and considers it a failure if all keys & values in it are not also in the metadata. This should make it possible to build workflow-related assertions and other metadata assertions much more easily.
05ffe68 to
9e07519
Compare
brandur
reviewed
Feb 11, 2026
Contributor
brandur
left a comment
There was a problem hiding this comment.
Oops, my fault on the delay here.
Just want to run one alt by you, but generally looks fine.
| // ignored. | ||
| // | ||
| // No assertion is made if left nil or empty. | ||
| Metadata map[string]any |
Contributor
There was a problem hiding this comment.
Just related to our convo last weekend, wanted to quickly get your thoughts on allowing people to do something like specify an exact match versus partial match.
If this became:
Metadata MetadataMatcherAnd you had something like:
type MetadataMatcher interface {
CheckMatch(t testingT, actualBytes []byte, requireNotInserted bool) (bool, []string)
}
type metadataContainsMatcher struct {
expected map[string]any
}
// MetadataContains checks that the given key-value pairs are present in job
// metadata, ignoring any extra keys that may also be there.
func MetadataContains(expected map[string]any) metadataContainsMatcher {
return metadataContainsMatcher{expected: expected}
}
type metadataExactlyMatcher struct {
expected map[string]any
}
// MetadataExactly checks that the given key-value pairs are present in job
// metadata, and that no extra keys are present.
func MetadataExactly(expected map[string]any) metadataExactlyMatcher {
return metadataExactlyMatcher{expected: expected}
}You get a pretty clean check that's a bit more readable than what's in here right now like:
opts.Metadata = MetadataContains(map[string]any{
"key": "value",
})The downside is that sometimes these interface-based checks can be a little hard to figure out how to use.
Thoughts?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This enables basic assertions against metadata in
rivertest.RequireXmethods. The approach here isn't anything special: it allows amap[string]anyto be specified and considers it a failure if all keys & values in it are not also in the metadata.This should make it possible to build workflow-related assertions and other metadata assertions much more easily.